import React, { Component } from 'react'
import axios from "axios"
import {connect} from "react-redux"
import Item from "../../Item/Item"

interface IProps{
    setlist:(list:Array<any>)=>void
    list:Array<any>
}

 class index extends Component<IProps> {
     componentDidMount(){
         axios.get("/list").then(res=>{
             console.log(res.data);
             this.props.setlist(res.data.data.lists)
         })
     }
    render() {
        let {list}=this.props
        console.log(list);
        return (
            <div className="index">
                <div className="bin">

                </div>
                {
                    list&&
                    list.map((item:any)=>{
                        return <Item
                                key={item.id}
                                info={item.info}
                                username={item.createVoteUserInfo.username}
                                title={item.title}
                                size={item.size}
                                endtime={item.endtime}
                                createtime={item.createtime}
                                selected={item.selected}
                                select={item.select}
                                id={item.id}
                        ></Item>
                    })
                }
            </div>
        )
    }
}

const mapstate=(state:any)=>{
    return {
        list:state.list
    }
}
const mapdispatch=(dispatch:any)=>{
    return {
        setlist(list:Array<any>){
            console.log(list);
            dispatch({type:"LIST",list})
        }
    }
}
export default connect(mapstate,mapdispatch)(index)
